package com.ruoyi.common.minio.config;

import com.ruoyi.common.minio.properties.MinioProperties;
import com.ruoyi.common.minio.utils.MinioUtils;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
@EnableConfigurationProperties(MinioProperties.class)
@ConditionalOnProperty(value = "my-minio.enabled", havingValue = "true")
public class MinioConfig {
//    @Value("my-minio.endPoint")
//    private String endPoint;
//    @Value("my-minio.bucketName")
//    private String bucketName;
//    @Value("my-minio.accessKey")
//    private String accessKey;
//    @Value("my-minio.secretKey")
//    private String secretKey;
    @Autowired
    MinioProperties minioProperties;
    private MinioClient minioClient;
    @Bean
    public MinioUtils createMinio(){
        minioClient = MinioClient.builder()
            .endpoint(minioProperties.getEndPoint())
            .credentials(minioProperties.getAccessKey(),minioProperties.getSecretKey())
            .build();
        return new MinioUtils(minioClient, minioProperties);
    }
}
